package com.wy.Service.impl;

import com.wy.Service.PostionService;
import com.wy.dao.PostionDao;
import com.wy.pojo.Postion;
import com.wy.vo.PageVo;
import com.wy.vo.PostionDto;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
public class PostionServiceImpl extends BaseServiceImpl implements PostionService {
    @Resource
    private PostionDao postionDao;
    @Override
    public List<Postion> findAll() {
        return postionDao.findAll();
    }

    @Override
    public void add(Postion postion) {
        postionDao.save(postion);
    }

    @Override
    public void delete(Integer id) {
        postionDao.deleteById(id);
    }

    @Override
    public List<Postion> findBId(Integer id) {
        return postionDao.findBId(id);
    }

    @Override
    public PageVo searchPage(Integer current, Integer pageSize, PostionDto dto) {
        StringBuilder sbd=new StringBuilder("select r from Postion r  where 1=1 ");
        if(!StringUtils.isEmpty(dto.getName())){
            sbd.append(" and r.name like :name");
            dto.setName("%"+dto.getName()+"%");
        }
        return super.searchPagination(current,pageSize,sbd.toString(),dto);
    }

    @Override
    public void update(Postion postion) {
        postionDao.save(postion);
    }
}
